using Assets.Scripts.GDK;
using UnityEngine;

namespace Brick
{
	public class Fangshe : gdk_base_UI
	{
		public TiggerBox trigger;

		private bool isTrigger;

		private bool isRecive;

		public override void OnLoad()
		{
			gdk_game_manager.AddEventListener(EventID.GAME_SHOOP_START, OnShotStart);
		}

		public override void UnLoad()
		{
			gdk_game_manager.RemoveEventListener(EventID.GAME_SHOOP_START, OnShotStart);
		}

		public void OnRestart()
		{
			trigger.isTrigger = false;
			isRecive = false;
		}

		private void OnShotStart()
		{
			OnShoot();
		}

		public void OnShoot()
		{
			if (trigger.isTrigger && !isRecive)
			{
				isRecive = true;
				EnemyPool.GetInstance().RecycleObj(base.gameObject);
				UnityEngine.Object.Destroy(base.gameObject);
			}
		}

		private void OnTriggerEnter2D(Collider2D other)
		{
			trigger.isTrigger = true;
			Rigidbody2D component = other.GetComponent<Rigidbody2D>();
			if (component == null)
			{
				return;
			}
			CircleCollider2D component2 = other.GetComponent<CircleCollider2D>();
			if (!component2.isTrigger)
			{
				Vector2 velocity = component.velocity;
				Vector2 a = new Vector2(0f, 1f);
				switch (Random.Range(0, 3))
				{
					case 0:
						a = new Vector2(0f, 1f);
						break;
					case 1:
						a = new Vector2(1f, 1f);
						break;
					case 2:
						a = new Vector2(-1f, 1f);
						break;
				}
				velocity = a * 1000f;
				if (velocity != Vector2.zero)
				{
					component.velocity = velocity;
				}
			}
		}
	}
}

